﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace EditTable
{
    public partial class FormAddNew : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        
        }

        protected bool AddCategory()
        {        
            if (this.textBoxDescription.Text != String.Empty && this.textBoxName.Text != String.Empty)
            {
                if (this.textBoxName.Text.Length > 15)
                {
                    Response.Write("Category name length is 15!");
                }
                else
                {
                    Category newCategory = new Category()
                    {
                        CategoryName = this.textBoxName.Text,
                        Description = this.textBoxDescription.Text
                    };
                    NorthWindClass.AddCategory(newCategory);
                    return true;
                }
            }
            return false;
        }

        protected void ButtonAdd_Click(object sender, EventArgs e)
        {
            if (AddCategory())
            {
                Response.Redirect("FormView.aspx");
            }
            else
            {
                Response.Write("Empty textboxes!");
            }
        }

        protected void ButtonCancel_Click(object sender, EventArgs e)
        {
            Response.Redirect("FormView.aspx");
        }
    }
}